
** Import raw data
infile using "$rawpath\NLSY79_week_hourswork\NLSY79_week_hourswork.dct", clear

** To get labels
run "$rawpath\NLSY79_week_hourswork\NLSY79_week_hourswork-value-labels.do"

tolower

rename r0000100 mom_pid
rename r0173600 sample_id_1979 
rename r0214700 race 
rename r0214800 sex


*keep women only
keep if sex == 2
*drop military sample -- keep black/poor oversample for now
*drop if sample_id_1979 > 15
*line below kills the supplemental sample
*drop if sample_id_1979 > 8

** Hours worked at all jobs before 1978
replace w0002000=. if w0002000<0
rename w0002000 hrs_worked_before1978


** Rename week worked variables in friendly format week X of year YYYY, from 1978 to 2017

* Some labels with incorrect year
label var w1138700 "HOURS AT ALL JOBS (2009) WEEK 1664"
label var w1142300 "HOURS AT ALL JOBS (2010) WEEK 1700"

desc w0002100- w1367400, varlist

local week = 0
local year0 = 1978
foreach var in `r(varlist)' {

	replace `var'=. if `var'<0
	
	local varlabel : variable label `var'
	local year = substr("`varlabel'",20,4)
	if `year'==`year0' {
		local ++week
		rename `var' hrs_worked_`year'_`week'
		local year0 = `year'
	}
	else {
		local week = 1
		rename `var' hrs_worked_`year'_`week'
		local year0 = `year'
	}

}

drop sample_id_1979 race sex

save "$rawpath\000_NLSY79_week_hourswork.dta", replace
